home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000…tember: Reference Library / Dev.CD Sep 00 RL Disk 1.toast / mac / What's New / • What was new 08⁄00 / Sample Code / Interapplication Comm / MoreOSL / MoreWindows / MoreWindows.cp next >
Encoding:
Text File  |  2000-06-23  |  3.2 KB  |  130 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        MoreWindows.cp
  3.  
  4.     Contains:    
  5.  
  6.     Written by:    Pete Gontier
  7.  
  8.     Copyright:    Copyright (c) 1998 Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.  
  20.          <5>     20/3/00    Quinn   Added GetWindowList for non-Carbon clients.
  21.          <4>      2/9/99    PCG     more TARGET_CARBON
  22.          <3>     1/25/99    PCG     TARGET_CARBON
  23.          <2>    11/11/98    PCG     fix header
  24.          <1>    11/10/98    PCG     first big re-org at behest of Quinn
  25.  
  26.     Old Change History (most recent first):
  27.  
  28.          <2>     7/24/98    PCG        eliminate dependency on 'qd'
  29.          <1>     6/16/98    PCG     initial checkin
  30. */
  31.  
  32. #include "MoreQuickDraw.h"
  33. #include "MoreWindows.h"
  34. #include "MoreAppearance.h"
  35.  
  36. #include <Controls.h>
  37. #include <Menus.h>
  38. #include <LowMem.h>
  39.  
  40. pascal OSStatus MoveWindowToAlertPosition (WindowRef window)
  41. {
  42.     OSStatus err = noErr;
  43.  
  44.     if (!MoreAssert (HaveAppearance ( ) || IsWindowVisible (window)))
  45.         err = paramErr;
  46.     else
  47.     {
  48.         Rect screenRect = (**GetMainDevice ( )).gdRect;
  49.         screenRect.top += GetMBarHeight ( );
  50.         InsetRect (&screenRect,4,4);
  51.  
  52.         Rect contRect;
  53.  
  54. #if !TARGET_CARBON
  55.  
  56.         if (!HaveAppearance ( ) || IsWindowVisible (window))
  57.             contRect = (**(((WindowPeek)window)->contRgn)).rgnBBox;
  58.         else
  59.  
  60. #endif
  61.  
  62.         {
  63.             RgnHandle contRgn = NewRgn ( );
  64.  
  65.             if (!contRgn)
  66.                 err = QDError ( );
  67.             else
  68.             {
  69.                 err = GetWindowRegion (window,kWindowContentRgn,contRgn);
  70.                 GetRegionBounds (contRgn,&contRect);
  71.                 DisposeRgn (contRgn);
  72.                 (void) MoreAssert (noErr == QDError ( ));
  73.             }
  74.         }
  75.  
  76.         if (!err)
  77.         {
  78.             Point windLoc;
  79.  
  80.             windLoc.v    = screenRect.top + ((screenRect.bottom - screenRect.top) / 3);
  81.             windLoc.h    = screenRect.left + ((screenRect.right - screenRect.top) / 2);
  82.  
  83.             windLoc.v    -= (contRect.bottom - contRect.top) / 2;
  84.             windLoc.h    -= (contRect.right - contRect.left) / 2;
  85.  
  86.             MoveWindow (window, windLoc.h, windLoc.v, true);
  87.         }
  88.     }
  89.  
  90.     return err;
  91. }
  92.  
  93. pascal OSErr MoreNewWindow (    const Rect *            boundsRect,
  94.                                 ConstStr255Param         title,
  95.                                 short                     theProc,
  96.                                 Boolean                 goAwayFlag,
  97.                                 long                     refCon,
  98.                                 WindowRef                *window            )
  99. {
  100.     OSErr err = noErr;
  101.  
  102.     if (!title)
  103.         title = "\p";
  104.  
  105.     if (HaveColorQuickDraw ( ))
  106.         *window = NewCWindow (nil,boundsRect,title,false,theProc,(WindowRef)kFirstWindowOfClass,goAwayFlag,refCon);
  107.     else
  108.         *window = NewWindow (nil,boundsRect,title,false,theProc,(WindowRef)kFirstWindowOfClass,goAwayFlag,refCon);
  109.  
  110.     if (!*window)
  111.         err = nilHandleErr;
  112.     else if (HaveAppearance ( ))
  113.     {
  114.         ControlRef dontCare;
  115.         err = CreateRootControl (*window,&dontCare);
  116.         if (err) DisposeWindow (*window);
  117.     }
  118.  
  119.     return err;
  120. }
  121.  
  122. #if !TARGET_API_MAC_CARBON
  123.  
  124.     extern pascal WindowRef GetWindowList(void)
  125.     {
  126.         return LMGetWindowList();
  127.     }
  128.  
  129. #endif
  130.